﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Inventario_HardSoft.ADO;
using Inventario_HardSoft.Controlador;

namespace Inventario_HardSoft
{
    public partial class Form1 : Form
    { 
        private Ctrl_login controlador; 
        public Form1()
        {
            InitializeComponent();
            controlador = new Ctrl_login();
        }         

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close(); 
        }

        private void button1_Click(object sender, EventArgs e)
        { 
          progressBar1.Visible = true;
            for(int i=0; i<=100; i++)
            {
                progressBar1.Minimum=0;
                progressBar1.Maximum = 100;
                progressBar1.Step = 5;
                progressBar1.PerformStep();
            }
            this.login();
        }
         
        private void login() 
        {
            String u = txtusu.Text;
            String p = txtclave.Text;
            USUARIO repa = controlador.validarUsuario(u, p);
            if (repa != null)
            {
                //Arranca el aplicativo
                this.Hide();
                //Abrimos Principal
                Principal princ = new Principal(repa);
                princ.Show();
            }
            else
            {
                    //mostramos mensaje
                    MessageBox.Show("Usuario o password es incorrecto o no existe", "Camilo - Login", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1);
                    progressBar1.Value = progressBar1.Minimum;
                    txtusu.Text="";
                    txtclave.Text = "";
                    txtusu.Focus(); 
            } 
        }

        private void Form1_Load(object sender, EventArgs e)
        {

        } 
    }
}
